package com.wanmait.recruit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.mapper.CompanyAuthcMapper;
import com.wanmait.recruit.pojo.Company;
import com.wanmait.recruit.pojo.CompanyAuthc;
import com.wanmait.recruit.pojo.Person;
import com.wanmait.recruit.service.CompanyAuthcService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("companyAuthcService")
@Transactional(rollbackFor = Exception.class)
public class CompanyAuthcServiceImpl implements CompanyAuthcService {

    @Resource
    CompanyAuthcMapper companyAuthcMapper;
    @Override
    public void insert(CompanyAuthc object) {
        companyAuthcMapper.insertSelective(object);
    }

    @Override
    public void delete(CompanyAuthc object) {

    }

    @Override
    public void update(CompanyAuthc object) {

    }

    @Override
    public PageInfo<CompanyAuthc> search(int pageNum, int pageSize) {
        return null;
    }

    @Override
    public CompanyAuthc findByCompany(Company company) {
        return companyAuthcMapper.findByCompanyId(company.getId());
    }

    @Override
    public PageInfo<CompanyAuthc> findAll(String companyAuthcName, Integer pageNum) {
        int pageSize = 10;
        PageHelper.startPage(pageNum,pageSize);
        List<CompanyAuthc> companyAuthcs = companyAuthcMapper.findAll(companyAuthcName);
        PageInfo<CompanyAuthc> pageInfo = new PageInfo<>(companyAuthcs,11);
        return pageInfo;
    }

    @Override
    public void isPass(Integer id) {
        companyAuthcMapper.isPass(id);
    }

    @Override
    public void notPass(Integer id, String reason) {
        CompanyAuthc companyAuthc = new CompanyAuthc();
        companyAuthc.setId(id);
        companyAuthc.setReason(reason);
        companyAuthcMapper.notPass(companyAuthc);
    }

    @Override
    public void deleteById(Integer id) {
        companyAuthcMapper.deleteById(id);
    }

    @Override
    public Person findPersonById(Integer id) {
        return companyAuthcMapper.findPersonById(id);
    }
}
